from django.contrib import admin

# Things needed from NoPBX
from nopbx.device.models import DeviceType, Manufacturer, Model, Device, Line
from nopbx.dialplan.models import Extension
from nopbx.infrastructure.models import Location

#
# Model admin page customization
#
class ModelInline(admin.StackedInline):
    model = Model
#    fields = ('name', 'description', 'device_type', 'max_lines')
    extra = 1
    exclude = ('plugins',)

    fieldsets = [
        (None, {
            'fields': ['name', 'description', 'device_type', 'max_lines'],
        }),
        ('Advanced', {
            'description': 'These options override the defaults that are configured for this device model.',
            'fields':  ['firmware', 'dial_template', 'softkey_template'],
            'classes': ['collapse', 'wide']
        }),
        ('URLs', {
            'description': 'Some devices support dynamic content via URLs. These options override the default URLs configured for this device model.',
            'fields':  ['url_auth', 'url_directory', 'url_idle', 'url_info', 'url_messages'],
            'classes': ['collapse']
        }),
    ]

#
# Manufacturer admin page customization
#
class ManufacturerAdmin(admin.ModelAdmin):
    list_display = ('name', 'description')
    inlines      = [ModelInline]

    fieldsets = [
        (None, {"fields": ('name', 'description')}),
    ]
admin.site.register(Manufacturer, ManufacturerAdmin)


#
# Device admin page customization
#
#class LineInline(admin.StackedInline):
class LineInline(admin.TabularInline):
    model = Line
    extra = 1
    exclude = ('username', 'password', 'plugins')

#    fieldsets = [
#        (None, {'fields': ['index', 'exten', 'caller_id', 'description']}),
#    ]

class DeviceAdmin(admin.ModelAdmin):
    list_display = ('description', 'mac_address', 'model', 'enabled')
    list_display_links = ('description', 'mac_address')

    fieldsets = [
        (None, {'fields': ['mac_address', 'description', 'model', 'location']}),
        ('Advanced', {
            'description': 'These options override the defaults that are configured for this device model.',
            'fields':  ['firmware', 'dial_template', 'softkey_template'],
            'classes': ['collapse', 'wide']
        }),
        ('URLs',      {
            'description': 'Some devices support dynamic content via URLs. These options override the default URLs configured for this device model.',
            'fields':  ['url_auth', 'url_directory', 'url_idle', 'url_info', 'url_messages'],
            'classes': ['collapse']}),
        ('Inventory', {
            'fields':  ['serial', 'asset_tag'],
            'classes': ['collapse']
        }),
    ]
    inlines = [LineInline]

admin.site.register(Device, DeviceAdmin)

